<?php


namespace App\Http\Controllers\Admin\UserManager;

use App\Response\Response;
use Illuminate\Http\Request;
use App\Exceptions\BasicException;
use App\Http\Controllers\BaseController;

//二级开屏
class UserUntieBanClassifyController extends BaseController
{
    /**
     * @Desc:列表
     * @param  Request  $request
     * @return string
     * @throws BasicException
     * @author: shiquan
     * @Time: 2022/11/3 15:52
     */
    public function list(Request $request)
    {
        $param = $request->only(['page', 'page_size']);
        $v = app('validator')->make($param, [
            'page' => 'integer|min:1',
            'page_size' => 'integer|min:1',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $list = app('repo_user_untie_ban_classify')->list($param);
        return Response::sendList($list);
    }

    /**
     * @Desc:详情
     * @param  Request  $request
     * @return string
     * @throws BasicException
     * @author: shiquan
     * @Time: 2022/11/3 15:52
     */
    public function info(Request $request)
    {
        $param = $request->only('id');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|exists:mysql.ln_user_ban_classify,id',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $list = app('repo_user_untie_ban_classify')->info($param);
        return Response::sendData($list);
    }

    /**
     * @Desc:新增
     * @param  Request  $request
     * @return string
     * @throws BasicException
     * @author: shiquan
     * @Time: 2022/11/3 15:52
     */
    public function create(Request $request)
    {
        $param = $request->only([
            'title',
        ]);
        $v = app('validator')->make($param, [
            'title' => 'required|string|min:1|max:255',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_user_untie_ban_classify')->create($param);
        return Response::sendData(true);
    }

    /**
     * @Desc:更新
     * @param  Request  $request
     * @return string
     * @throws BasicException
     * @author: shiquan
     * @Time: 2022/11/3 15:52
     */
    public function update(Request $request)
    {
        $param = $request->only([
            'id',
            'title',
        ]);
        $v = app('validator')->make($param, [
            'id' => 'required|integer|exists:mysql.ln_user_ban_classify,id',
            'title' => 'required|string|min:1|max:255',
        ]);

        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());
        $list = app('repo_user_untie_ban_classify')->update($param);
        return Response::sendData($list);
    }

    /**
     * @Desc:删除
     * @param  Request  $request
     * @return string
     * @throws BasicException
     * @author: shiquan
     * @Time: 2022/11/3 15:52
     */
    public function delete(Request $request)
    {
        $param = $request->only(['ids']);
        $v = app('validator')->make($param, [
            'ids' => 'required|array',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_user_untie_ban_classify')->delete($param);
        return Response::sendData(true);
    }
}